package edu.hawaii.senin.iclouds.simple;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.Before;
import org.junit.Test;

import edu.hawaii.senin.iclouds.basics.ReadConfigException;

/**
 * Tests appropriate coniguration parsing.
 * 
 * @author Pavel Senin.
 * 
 */
public class TestReadConfigParameters {

  private static final String configName1 = "config/test_cfg/test001.xml";
  private Cloud testCloud;

  /**
   * Makes setup fixture.
   * 
   */
  @Before
  public void setUp() {
    this.testCloud = new Cloud();
  }

  /**
   * Tests correct variables extraction.
   * 
   * 
   */
  @Test
  public void testLoadPhysicalParameters() {
    try {
      CloudParametersMessage cm = new CloudParametersMessage();
      cm.addParameter(CloudParametersMessage.CFGNAME, configName1);
      testCloud.setParameters(cm);
    }
    catch (ReadConfigException e) {
      fail("Got error parsing config file : " + e.getMessage());
    }
    CloudParametersMessage cp = testCloud.getCloudParameters();
    assertEquals("testing T getter", Double.valueOf(1E+1), Double.valueOf(cp
        .get(CloudParametersMessage.TEMPERATURE)));
    assertEquals("testing D getter", Double.valueOf(1E+3), Double.valueOf(cp
        .get(CloudParametersMessage.DENSITY)));
    assertEquals("testing Grain num getter", Double.valueOf(1E+6).intValue(), Integer.valueOf(cp
        .get(CloudParametersMessage.SITESNUM)));
    assertEquals("testing Grain size getter", Double.valueOf(1E+3), Double.valueOf(cp
        .get(CloudParametersMessage.GRAINSIZE)));
    assertEquals("testing iterations Limit getter", Double.valueOf(1E+6).intValue(), Integer
        .valueOf(cp.get(CloudParametersMessage.ITRLIMIT)));
    assertEquals("testing accretion Step getter", Double.valueOf(1E+6).intValue(), Integer
        .valueOf(cp.get(CloudParametersMessage.ACCSTEP)));

  }

}
